package com.shenda.device.handler;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.shenda.device.handler.handlers.ConfigHandler;
import com.shenda.device.handler.handlers.FlushHandler;
import com.shenda.device.handler.handlers.GetMacHandler;
import com.shenda.device.handler.handlers.GetPinHandler;
import com.shenda.device.handler.handlers.RebootHandler;
import com.shenda.device.handler.handlers.StartCollectionHandler;
import com.shenda.device.handler.handlers.StartUploadHandler;
import com.shenda.device.handler.handlers.StopCollectionHandler;
import com.shenda.device.handler.handlers.StopUploadHandler;
import com.shenda.device.handler.handlers.UploadDataHandler;
import com.shenda.device.handler.handlers.UploadStartHandler;
import com.shenda.device.message.RespMsg;

/**
 * 
 * 设备处理器
 * 
 * @author lifeng
 */
@Component
public class Handlers implements InitializingBean, Handler {

	@Autowired
	GetMacHandler getMacHandler;
	@Autowired
	GetPinHandler getPinHandler;
	@Autowired
	ConfigHandler configHandler;
	@Autowired
	FlushHandler flushHandler;
	@Autowired
	RebootHandler rebootHandler;
	@Autowired
	StartCollectionHandler startCollectionHandler;
	@Autowired
	StartUploadHandler startUploadHandler;
	@Autowired
	StopCollectionHandler stopCollectionHandler;
	@Autowired
	StopUploadHandler stopUploadHandler;
	@Autowired
	UploadStartHandler uploadStartHandler;
	@Autowired
	UploadDataHandler uploadDataHandler;

	@Override
	public void afterPropertiesSet() throws Exception {
		getMacHandler.chain(getPinHandler).chain(configHandler).chain(flushHandler).chain(rebootHandler)
				.chain(startCollectionHandler).chain(startUploadHandler).chain(stopCollectionHandler)
				.chain(stopUploadHandler).chain(uploadStartHandler).chain(uploadDataHandler);
	}

	/**
	 * 委托自定义处理器处理
	 */
	@Override
	public void doHandle(RespMsg resp) {
		getMacHandler.doHandle(resp);
	}
}